//
//  DDDetailsBottomView.m
//  Dingdong
//
//  Created by 程强 on 16/11/28.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDDetailsBottomView.h"

@interface DDDetailsBottomView()
@property (strong, nonatomic) UIButton *addToCartBtn;
@property (strong, nonatomic) UIButton *buyNowBtn;
@property (strong, nonatomic) UIImageView *collectionIcon;
@property (assign, nonatomic) DingDongDetailsOperationType operationType;
@end

@implementation DDDetailsBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        weak_Self(self);
        
        UIView *line = [[UIView alloc]init];
        line.backgroundColor = RGBColor(237, 237, 237);
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf);
            make.centerX.width.equalTo(weakSelf);
            make.height.equalTo(@1);
        }];
        
//        self.buyNowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [_buyNowBtn setBackgroundImage:LoadImage(@"buynow") forState:UIControlStateNormal];
//        [_buyNowBtn setTitle:@"Buy Now" forState:UIControlStateNormal];
//        [self addSubview:_buyNowBtn];
//        [_buyNowBtn addTarget:self action:@selector(buyClick:) forControlEvents:UIControlEventTouchUpInside];
//        [_buyNowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.width.equalTo(@105);
//            make.height.equalTo(@50);
//            make.centerY.equalTo(weakSelf);
//            make.right.equalTo(self);
//        }];
        
        self.addToCartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addToCartBtn setBackgroundImage:LoadImage(@"add_to_cart") forState:UIControlStateNormal];
        [_addToCartBtn setTitle:@"Add To Cart" forState:UIControlStateNormal];
        [self addSubview:_addToCartBtn];
        [_addToCartBtn addTarget:self action:@selector(addCartClick:) forControlEvents:UIControlEventTouchUpInside];
        [_addToCartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@200);
            make.height.equalTo(@50);
            make.centerY.equalTo(weakSelf);
            make.right.equalTo(weakSelf);
        }];
        
        
        UIView *leftView = [[UIView alloc]init];
        [self addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(weakSelf);
            make.right.equalTo(weakSelf.addToCartBtn.mas_left);
        }];
        
        _collectionIcon = [[UIImageView alloc]init];
        _collectionIcon.image = LoadImage(@"details_un_collection");
        _collectionIcon.highlightedImage = LoadImage(@"details_collection");
        [leftView addSubview:_collectionIcon];
        [_collectionIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@16);
            make.height.equalTo(@14);
            make.centerX.equalTo(leftView.mas_centerX).multipliedBy(0.5);
            make.top.equalTo(self).offset(12);
        }];
        
        KKLabel *collectionLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"Wish",[UIColor blackColor],[UIFont systemFontOfSize:12.0],NSTextAlignmentCenter);
        }];
        [leftView addSubview:collectionLbl];
        [collectionLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_collectionIcon.mas_bottom);
            make.centerX.equalTo(_collectionIcon);
            make.height.equalTo(@25);
            make.width.equalTo(leftView.mas_width).multipliedBy(0.5);
        }];
        
        UIButton *collectionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [leftView addSubview:collectionBtn];
        [collectionBtn addTarget:self action:@selector(addWish:) forControlEvents:UIControlEventTouchUpInside];
        [collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(leftView);
            make.width.equalTo(leftView.mas_width).multipliedBy(0.5);
        }];
        
        UIImageView *consultIcon = [[UIImageView alloc]init];
        consultIcon.image = LoadImage(@"details_pinglun");
        [leftView addSubview:consultIcon];
        [consultIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@15);
            make.height.equalTo(@14);
            make.centerX.equalTo(leftView.mas_centerX).multipliedBy(1.5);
            make.top.equalTo(self).offset(12);
        }];
        
        KKLabel *consultLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"Consult",[UIColor blackColor],[UIFont systemFontOfSize:12.0],NSTextAlignmentCenter);
        }];
        [leftView addSubview:consultLbl];
        [consultLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(consultIcon.mas_bottom);
            make.centerX.equalTo(consultIcon);
            make.height.equalTo(@25);
            make.width.equalTo(leftView.mas_width).multipliedBy(0.5);
        }];
        
        UIButton *consultBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [leftView addSubview:consultBtn];
        [consultBtn addTarget:self action:@selector(consultClick:) forControlEvents:UIControlEventTouchUpInside];
        [consultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(leftView);
            make.width.equalTo(leftView.mas_width).multipliedBy(0.5);
        }];
    }
    return self;
}
- (void)addWish:(UIButton *)btn
{
    [self didSelectWithType:DingDongDetailsOperationTypeWish];
}
- (void)consultClick:(UIButton *)btn
{
    [self didSelectWithType:DingDongDetailsOperationTypeConsult];
}
- (void)buyClick:(UIButton *)btn
{
    [self didSelectWithType:DingDongDetailsOperationTypeBuyNow];
}
- (void)addCartClick:(UIButton *)btn
{
    [self didSelectWithType:DingDongDetailsOperationTypeAddToCart];
}
- (void)didSelectWithType:(DingDongDetailsOperationType)type
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(bottomView:didOperationWithType:)]) {
        [self.delegate bottomView:self didOperationWithType:type];
    }
}
- (void)setWished:(BOOL)wished
{
    _wished = wished;
    _collectionIcon.highlighted = wished;
}
@end
